package com.example.reone.mydatapicker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import java.util.Calendar;

public class MainActivity extends Activity {

    private View _showBtn;
    private DataPickerDialog _dataPickerDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        _showBtn = findViewById(R.id.show_data_picker_btn);
        initMyDialog();
        _showBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showMyDialog();
            }
        });
    }
    private void initMyDialog(){
        _dataPickerDialog = new DataPickerDialog();
//        _dataPickerDialog.initDate(2013,3,27,18,00,null);
        _dataPickerDialog.setOnDataPickerListener(new DataPickerDialog.OnDataPickerListener() {
            @Override
            public void onSure(Calendar currentCalendar, String currentFormat,String date,String time) {
                Toast.makeText(MainActivity.this,date + " " + time,Toast.LENGTH_SHORT).show();
                _dataPickerDialog.dismiss();
            }

            @Override
            public void onCancel() {
                _dataPickerDialog.dismiss();
            }
        });
    }
    private void showMyDialog(){
        _dataPickerDialog.show(getFragmentManager(),"myDialog");
    }
}
